import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait


def wait_sleep():
    driver=webdriver.Chrome()
    driver.get("https://vip.ceshiren.com/#/ui_study/locate")
    #强制等待
    # time.sleep(3)
    #隐式等待  注意：1.全局生效，只能在find_element之前  2.只能解决元素查找问题，不能解决元素交互
    driver.implicitly_wait(3)
    driver.find_element(By.XPATH,"/html/body/div/div/section/section/aside/div/ul/li[5]/a")

def wait_show():
    driver = webdriver.Chrome()
    driver.get("https://vip.ceshiren.com/#/ui_study/locate")

    #显示等待   WebDriverWait(driver实例,最长等待时间,轮询时间).until(结束条件)
    el=WebDriverWait(driver, 10).until(
        expected_conditions.element_to_be_clickable((By.ID,"locate_id"))
    )
    driver.find_element(By.ID,"locate_id").click()   #el.click()
    #文本属性
    print(el.text)
    #取name属性
    print(el.get_attribute("name"))
    time.sleep(3)

if __name__ == '__main__':
    # wait_sleep()
    wait_show()